<template>
  <div>
    <h3 class="dialog-plate-title mt-1"><span>病历</span></h3>
    <todayCase :hid="pid" @saveSuccess="saveSuccess" :todayCaseObj="todayCaseObj"></todayCase>              
    <h3 class="dialog-plate-title mt-1" ><span>历史病历</span></h3>
    <el-table :data="historicalCasesList" stripe border class="company-table"  style="width: 95%;">
      <el-table-column prop="selfAbout" label="主诉" sortable min-width="90"></el-table-column>
      <el-table-column prop="primaryDiagnosis" label="初步诊断" sortable min-width="110"></el-table-column>
      <el-table-column prop="treatmentOptions" label="治疗意见" sortable min-width="110"></el-table-column>
      <el-table-column prop="creatorName" label="接诊医师" sortable min-width="110"></el-table-column>
      <el-table-column prop="createTime" label="接诊日期" sortable min-width="110">
        <template slot-scope="scope">
          <div v-html="timestampToTime(scope.row.createTime,'yyyy-mm-dd hh:mm:ss')"></div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" min-width="110">
        <template slot-scope="scope">
          <el-button  type="text" size="small" @click="showCase(scope.row)">详情</el-button>
          <el-button  type="text" size="small" @click="print(scope.row)">打印病历</el-button>
          <el-button  type="text" size="small" @click="showCourseDisease(scope.row)">病程</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="caseDialog.title" :visible.sync="caseDialog.open" width="90%" top="70px" :close-on-clcick-modal="false" class="bodyNopaddingTop">
      <todayCase  :todayCaseObj="caseDialog.formdata" :disabled='true'></todayCase> 
    </el-dialog>
    <!-- 病程列表弹框 -->
    <el-dialog :title="courseDiseaseDialog.title" :visible.sync="courseDiseaseDialog.open" width="90%" top="70px" :close-on-clcick-modal="false" class="bodyNopaddingTop" @opened="opendCourseDiseaseDialog">
      <courseDisease :hid="courseDiseaseDialog.pid" ref="courseDisease"></courseDisease>
    </el-dialog>
     <div :ref="'print'" style="display:none"> 
         <div style="font-size:xx-large;text-align: center;margin:20px"> 门诊病历 </div> 
          <table  border="1" cellspacing="0" cellpadding="0"  style="font-size:large;text-align: left ;margin: auto;width:750px">  
              <tr>
                <td style="width:100px;text-align: center" >姓名:</td>
                <td>{{providerInfo.name}}</td>
                <td  style="text-align: center"  >门诊号:</td>
                <td>{{providerInfo.cardId}}</td>
                <td style="text-align: center" >年龄:</td>
                <td>{{providerInfo.age}}岁 </td>
              </tr>
              <tr>
                <td style="width:100px;text-align:center">性别:</td>
                <td>{{providerInfo.sex==='1'?'男':'女'}}</td>
                <td style="text-align: center" >身份证:</td>
                <td>{{providerInfo.idNo}}</td>
                <td style="text-align: center" >电话:</td>
                <td>{{providerInfo.phone}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center"> 地址: </td>
                <td  colspan="5" >{{providerInfo.address}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center"> 主诉: </td>
                <td  colspan="5" >{{recordInfo.selfAbout}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center"> 现病史: </td>
                <td  colspan="5" >{{recordInfo.nowDisease}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 既往史: </td>
                <td  colspan="5" >{{recordInfo.pastDisease}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 过敏史: </td>
                <td  colspan="5" >{{recordInfo.allergyHistory}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 个人史: </td>
                <td  colspan="5" >{{recordInfo.persionHistory}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center"  > 婚育史: </td>
                <td  colspan="5" >{{recordInfo.mfHistory}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 家族史: </td>
                <td  colspan="5" >{{recordInfo.familyHistory}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 体格检查: </td>
                <td  colspan="5" >{{recordInfo.bodyCheck}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 辅助检查: </td>
                <td  colspan="5" >{{recordInfo.auxiliaryCheck}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 初步诊断: </td>
                <td  colspan="5" >{{recordInfo.primaryDiagnosis}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 治疗意见: </td>
                <td  colspan="5" >{{recordInfo.treatmentOptions}}</td>
              </tr>
              <tr>
                <td colspan="1" style="width:100px;text-align:center" > 接诊医师: </td>
                <td  colspan="2" >{{recordInfo.creatorName}}</td>
                <td colspan="1" > 接诊日期: </td>
                <td  colspan="2" >{{recordInfo.createTime}}</td>
              </tr>
          </table>   
      </div>
      
  </div>
</template>
<script>
import {getHistoricalCases,getCacheTodayCase,getProviderInfo} from "plugins/axios/inquiryRecord.js";
// 病历form
import todayCase from 'views/operationManage/components/inquiryRecordDetail/casesReceived/todayCase.vue';
// 病程
import courseDisease from 'views/operationManage/components/inquiryRecordDetail/casesReceived/courseDisease.vue';
export default {
  components:{
    todayCase,
    courseDisease
  },
  props:{
    pid:{
     type:[String,Number]
    },
    providerId:{
      type:[String,Number]
    }
  },
  computed: {},
  data() {
    return {
      caseDialog:{
        formdata:{},
        open:false,
        title:''
      },
      courseDiseaseDialog:{
        pid:'',
        open:false,
        title:''
      },
      todayCaseObj:{},
      /**历史病例列表*/ 
      historicalCasesList:[],
      providerInfo:{},
      recordInfo:{},
    }
  },
  created() {},
  mounted(){},
  methods: {
   async   print(row){
       //查询基础信息
       let self =this;
        self.recordInfo=row;
       self.recordInfo.createTime=  self.timestampToTime( self.recordInfo.createTime,'yyyy-mm-dd hh:mm:ss')
       await  getProviderInfo(row.hid).then(res=>{
            self.providerInfo= res.content
          })
           self.$refs.print.style.display='inline';
            self.$print(self.$refs['print'])
            self.$refs.print.style.display='none';
　  
    },
    init(){
      this.getCacheTodayCase();
      this.getHistoricalCases();
    },
    saveSuccess(){
      this.init();
    },
    // 获取今日接诊病例
    getCacheTodayCase(){
      let self = this;
      getCacheTodayCase(self.pid).then(res=>{
        self.todayCaseObj=res.content;
      })
    },
    // 获取个人历史接诊病例
    getHistoricalCases(){
      let self = this;
      getHistoricalCases(self.providerId).then(res=>{
        self.historicalCasesList = res.content;
      })
    },
     /**显示病程列表弹框点击事件*/ 
    showCourseDisease(row){
      this.courseDiseaseDialog.title='病程'
      this.courseDiseaseDialog.open=true;
      this.courseDiseaseDialog.pid=row.id;
    },
    /**病程列表弹框打开后的回调函数*/ 
    opendCourseDiseaseDialog(){
      this.$refs.courseDisease.getDataList();
    },
    showCase(row){
      this.caseDialog.open=true
      this.caseDialog.formdata=row
      this.caseDialog.title="病历"
    }
  }
};
</script>
<style lang="stylus" scoped>
</style>